package com.alstudio.module.xmpp.protocol.xmpp.parser.iq.voip;

import com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALIQ;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.ALBaseIQParser;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.IQXmlParseEventCallback;
import com.alstudio.utils.formater.numeric.ALNumericUtils;
import com.alstudio.utils.log.ALLog;

/**
 * 本类用于解析拒绝来电
 * @author alonso lee
 *
 */
public class RejectVoipCallParser extends ALBaseIQParser implements
		IQXmlParseEventCallback {
	
	private int code = 0;
	private String sessionid = null;

	private final String SESSION_TAG = "sessionid";
	private final String CODE_TAG = "code";

	@Override
	public void parseIQPackage(ALIQ packact, String stream, ALXmppEventListener listener)
			throws Exception {
		// TODO Auto-generated method stub
		code = 0;
		sessionid = null;
		mListener = listener;

		startParse(packact, stream, this);
	}

	@Override
	public void processErrorStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals(ERROR_CODE_TAG)) {
			code = ALNumericUtils.parseInt(getAttValue("code"), 0);
		}
	}

	@Override
	public void processSetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	@Override
	public void processGetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	@Override
	public void processResultStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals(SESSION_TAG)) {
			sessionid = readText();
			ALLog.d("reject session " + sessionid);
		}
	}

	@Override
	public void processEndTag(String tag) {
		// TODO Auto-generated method stub

	}

	@Override
	public void processStartDocument() {
		// TODO Auto-generated method stub

	}

	@Override
	public void processEndDocument() {
		// TODO Auto-generated method stub
		onCallback();
	}

	@Override
	public void onCallback() {
		// TODO Auto-generated method stub
		if(mListener != null){
			mListener.onGetRejectVoipCallResult(sessionid);
		}
	}

}
